<meta charset="utf-8">
(#) Custom views in libraries should use res-auto-namespace

!!! ERROR: Custom views in libraries should use res-auto-namespace
   This is an error, and is also enforced at build time when
   supported by the build system. For Android this means it will
   run during release builds.

Id
:   `LibraryCustomView`
Summary
:   Custom views in libraries should use res-auto-namespace
Severity
:   Fatal
Category
:   Correctness
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   Initial
Affects
:   Manifest files and resource files
Editing
:   This check runs on the fly in the IDE editor
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/NamespaceDetector.kt)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NamespaceDetectorTest.kt)
Copyright Year
:   2012

When using a custom view with custom attributes in a library project,
the layout must use the special namespace
http://schemas.android.com/apk/res-auto instead of a URI which includes
the library project's own package. This will be used to automatically
adjust the namespace of the attributes when the library resources are
merged into the application project.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
res/layout/customview.xml:5:Error: When using a custom namespace
attribute in a library project, use the namespace
"http://schemas.android.com/apk/res-auto" instead [LibraryCustomView]
    xmlns:foo="http://schemas.android.com/apk/res/foo"
               --------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is the source file referenced above:

`res/layout/customview.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:other="http://schemas.foo.bar.com/other"
    xmlns:foo="http://schemas.android.com/apk/res/foo"
    android:id="@+id/newlinear"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" &gt;

    &lt;foo.bar.Baz
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        foo:misc="Custom attribute"
        tools:ignore="HardcodedText" &gt;
    &lt;/foo.bar.Baz&gt;

    &lt;!-- Wrong namespace uri prefix: Don't warn --&gt;
    &lt;foo.bar.Baz
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        other:misc="Custom attribute"
        tools:ignore="HardcodedText" &gt;
    &lt;/foo.bar.Baz&gt;

&lt;/LinearLayout&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/NamespaceDetectorTest.kt)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `NamespaceDetector.testCustom`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=192708.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Adding the suppression attribute `tools:ignore="LibraryCustomView"`
  on the problematic XML element (or one of its enclosing elements).
  You may also need to add the following namespace declaration on the
  root element in the XML file if it's not already there:
  `xmlns:tools="http://schemas.android.com/tools"`.

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="LibraryCustomView" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'LibraryCustomView'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore LibraryCustomView ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>